package com.demo.config;

/**
 * author:王蒙蒙
 * date创建日期:2025/7/24
 * 类注释说明:
 **/


import io.restassured.RestAssured;
import io.restassured.builder.RequestSpecBuilder;
import io.restassured.config.HttpClientConfig;
import io.restassured.config.RestAssuredConfig;
import io.restassured.specification.RequestSpecification;

public class RestAssuredGlobalConfig {

    private static boolean initialized = false;

    public static void init() {
        if (initialized) {
            return;
        }

        // 配置HTTP客户端超时
        HttpClientConfig httpClientConfig = HttpClientConfig.httpClientConfig()
                .setParam("http.socket.timeout", ApiConfig.TIMEOUT)
                .setParam("http.connection.timeout", ApiConfig.TIMEOUT);

        RestAssuredConfig config = RestAssured.config()
                .httpClient(httpClientConfig);

        // 设置全局配置
        RestAssured.config = config;

        // 创建默认请求规范（可选）
        RequestSpecification defaultSpec = new RequestSpecBuilder()
                .setBaseUri(ApiConfig.BASE_URL)
                .setContentType("application/json")
                .build();

        RestAssured.requestSpecification = defaultSpec;

        initialized = true;
    }

}
